package com.tbq.rebootapk;

import android.app.ActivityManager;
import android.content.Context;
import android.util.Log;

import java.util.List;

/**
 * Created by Administrator on 2015/7/23.
 */
public class TbqRuningNow {

    public static boolean runNow(Context context)
    {
//        //判断应用是否在运行
//        ActivityManager am = (ActivityManager)context.getSystemService(Context.ACTIVITY_SERVICE);
//        List<ActivityManager.RunningTaskInfo> list = am.getRunningTasks(100);
        boolean isAppRunning = false;
////        String MY_PKG_NAME = "com.cyberblue.iitag";
////        for (ActivityManager.RunningTaskInfo info : list) {
////            if (info.topActivity.getPackageName().equals(MY_PKG_NAME) || info.baseActivity.getPackageName().equals(MY_PKG_NAME)) {
////                isAppRunning = true;
////                Log.i("cjj123", info.topActivity.getPackageName() + " info.baseActivity.getPackageName()=" + info.baseActivity.getPackageName());
////                break;
////            }
////        }
//        Log.i("cjj456",""+isAppRunning);


        ActivityManager mActivityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE) ;
        //获得系统运行的进程
        List<ActivityManager.RunningAppProcessInfo> appList1 = mActivityManager
                .getRunningAppProcesses();
        for (ActivityManager.RunningAppProcessInfo running : appList1) {
            System.out.println(running.processName);
            if("com.community.games".equals(running.processName))
            {
                isAppRunning = true;
                break;
            }
        }
        System.out.println("================"+isAppRunning);
        return  isAppRunning;
    }



}
